<template>
  <el-dialog title="修改上级" :visible.sync="dialogVisible" class="dialog">
    <el-input
      v-model="parentId"
      placeholder="请输入上级id"
      style="width: 350px"
    />

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { _isMobile } from "@/utils/index";
import { updateParent } from "@/api/table";

export default {
  data() {
    return {
      dialogVisible: false,
      isMobile: _isMobile,
      parentId: null,
      userId: null,
    };
  },

  methods: {
    show(e) {
      console.log(e);
      this.dialogVisible = true;
      this.userId = e.id;
    },
    // 1070 改成1071  原来是 1015
    submit() {
      if (!this.parentId) {
        this.$message.error("请输入父级ID");
        return false;
      }
      this.$confirm("是否确认修改上级?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        updateParent({ parentId: this.parentId, userId: this.userId }).then(
          (res) => {
            this.dialogVisible = false;
            this.parentId = null;
            this.$parent.fetchData();
            this.$message({
              message: "操作成功",
              type: "success",
            });
          }
        );
      });
    },
  },
};
</script>
